<div class="alert-title">注单异常处理，对出现此问题深表抱歉，我们会尽快解决此问题</div>

<table class="balance-yc" style="width:100%;">
    <tr class="xx">
        <th>基本信息</td>
        <th width="300px">本期本游戏注单信息</th>
        <th width="450px">所有未处理账变</th>
        <th width="250px">后台手工充值记录</th>
    </tr>

    <tr>
        <td valign="top" style="padding-top:5px;">
            <div class="b-name">用户名：<span></span></div>
            <div class="b-balance">余额：<span></span></div>
            <div class="b-pending">未结余额：<span></span></div>
            <div class="b-game">游戏：<span></span></div>
            <div class="b-issue">期号：<span></span></div>
            <div class="b-bet">下注：<span></span></div>
            <div class="b-bet-amount">下注金额：<span></span></div>
        </td>
        <td valign="top" style="padding:5px;">
            <table class="am-table am-table-bordered am-table-radius am-table-striped" id="b-bet-table">
                <thead>
                    <tr>
                        <th>明细</th>
                        <th>金额</th>
                        <th>返水</th>
                        <th>结果</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </td>
        <td valign="top" style="padding:5px;">
            <table class="am-table am-table-bordered am-table-radius am-table-striped" id="b-balance-table">
                <thead>
                    <tr>
                        <th>类型</th>
                        <th>明细</th>
                        <th>金额</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </td>
        <td valign="top" style="padding:5px;">
            <table class="am-table am-table-bordered am-table-radius am-table-striped" id="b-charge-table">
                <thead>
                    <tr>
                        <th>明细</th>
                        <th>金额</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </td>
    </tr>
</table>
<div class="process-title">处理步骤。如果不是很清楚流程，请交给开发人员处理</div>

<ul>
    <ol>1、核对注单信息，确定本账变记录对应的注单，是否有中奖</ol>
    <ol>2、如果有中奖，但没有派奖，请到“余额变更”手工为其补全中奖金额</ol>
    <ol>
        3、核对用户的未结金额，如果未结金额为0，那么先为其补全未结金额（数量为本账变的金额）<br/>
        <input type="number" placeholder="请输入用户新的未结金额" class="input-weijie">
        <button class="btn-weijie">确定修改</button>
    </ol>
    <ol>4、点击按钮“审核通过”。请确保审核通过：当未结金额小于本账变记录的金额时，不会成功。</ol>
</ul>

<div class="button_line">
    <button class="btn-save common_button admin_button">审核通过</button>
    <button class="close common_button admin_button">关闭</button>
</div>
<style type="text/css">
    .balance-yc .xx th {
        color: black;
        font-size: 14px;
    }
    .process-title {
        line-height: 32px;
        border-top: 1px solid #ccc;
        border-bottom: 1px solid #ccc;
        font-size: 14px;
        font-weight: bold;
        color: #000;
    }
    .input-weijie {
        width: 200px;
    }
</style>

<script>
    $(".close").click(function() {
        $("#balance_yichang").remove();
    });

    function _queryAccountInfo(uid) {
        CMD.query_account(uid, '', function(r) {
            for (var i in r.list) {
                var d = r.list[i];
                if (d.owner != '') continue;

                $(".b-name span").html(d.user.mobile);
                $(".b-balance span").html(d.balance/100);
                $(".b-pending span").html(d.pending/100);
            }
        });
    }

    function _queryBet(uid, type, issue) {
        CMD.query_bet(type, "", {
            uid: uid,
            issues: issue + "," + issue,
            pageNum: 1,
            pageSize: 100,
        }, function(r) {
            var table = $("#b-bet-table tbody"); table.empty();
            for (var i in r.list) {
                var d = r.list[i];
                var tr = $("<tr></tr>");
                tr.append("<td>" + Util.convertTarget(d.type, d.target) + "</td>");
                tr.append("<td>" + d.amount/100 + "</td>");
                tr.append("<td>" + d.back/100 + "</td>");
                if (d.state == 0) tr.append("<td>" + '未结' + "</td>");
                else
                    tr.append("<td>" + d.profit/100 + "</td>");
                table.append(tr);
            }
        });
    }

    function _queryBalance(uid) {
        CMD.query_account_log({
            uid: uid,
            pageNum: 1,
            pageSize: 400,
            state: 0,
        }, function(r) {
            var table = $("#b-balance-table tbody"); table.empty();
            var total = 0;
            for (var i in r.list) {
                var d = r.list[i];
                var tr = $("<tr></tr>");
                tr.append("<td>" + Util.convertLogType(d.type) + (d.channel2 ? "/" + Util.convertChannel(d.channel2) : '') + "</td>");
                var memo = Util.convertMemo(d);
                tr.append("<td class='l'>" + memo + "</td>");
                tr.append("<td>" + d.amount/100 + "</td>");
                total += d.amount;
                table.append(tr);
            }

            var tr = $("<tr></tr>");
            tr.append("<td colspan='2'>合计</td>");
            tr.append("<td>" + total/100 + "</td>");
            table.append(tr);
        });
    }

    function _queryCharge(uid) {
        CMD.query_account_log({
            uid: uid,
            pageNum: 1,
            pageSize: 400,
            state: 1,
            type: 'deposit',
            channel: 'handOper',
            channel2: 'manual'
        }, function(r) {
            var table = $("#b-charge-table tbody"); table.empty();
            for (var i in r.list) {
                var d = r.list[i];
                var tr = $("<tr></tr>");
                var memo = Util.convertMemo(d);
                tr.append("<td class='l'>" + memo + "</td>");
                tr.append("<td>" + d.amount/100 + "</td>");
                table.append(tr);
            }
        });
    }

    (function() {
        var log = context.center.balanceLog;
        _queryAccountInfo(log.user.mobile);

        var type = log.lottery;
        var issue = log.issue;
        $(".b-game span").html(get_game_display_name(type));
        $(".b-issue span").html((issue));
        $(".b-bet span").html(log.memo || '');
        $(".b-bet-amount span").html(log.amount/100);
        _queryBet(log.user.mobile, type, issue);

        _queryBalance(log.user.mobile);
        _queryCharge(log.user.mobile);
    })();

    $(".btn-weijie").click(function() {
        if (!confirm("慎重慎重！！！确定修改用户的未结余额吗？")) return;
        var v = $("input.input-weijie").val();
        if (v == '') return;
        v = v * 100;
        startLoading();
        CMD.account_pending(context.center.balanceLog.user.id, '', v, function(r) {
            stopLoading();
            _queryBalance(context.center.balanceLog.user.mobile);
        });
    });

    $(".btn-save").click(function() {
        if (!confirm("慎重慎重！！！确定审核通过本单据？一旦审核通过，将扣除用户对应数量的“未结余额”")) return;
        CMD.pass_account_log(context.center.balanceLog.id, function() {
            $("#balance_yichang").remove();
            if (window._f) _f();
        });
    })
</script>